<?php
class Atur_kelas extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}

	function kelas($id_m_th_ajaran)
	{
		$this->db->select('id_a_kelas,a_kelas.id_m_th_ajaran,th_ajaran,a_kelas.id_m_kelas,kelas,a_kelas.id_m_pegawai,nama_lengkap');
		$this->db->from('a_kelas');
		$this->db->join('m_th_ajaran', 'm_th_ajaran.id_m_th_ajaran = a_kelas.id_m_th_ajaran');
		$this->db->join('m_kelas', 'm_kelas.id_m_kelas = a_kelas.id_m_kelas');
		$this->db->join('m_pegawai', 'm_pegawai.id_m_pegawai = a_kelas.id_m_pegawai');
		$this->db->where('a_kelas.id_m_th_ajaran', $id_m_th_ajaran);
		$this ->db->order_by('id_m_kelas');

		$query = $this->db->get();		
		return $query->result();
	}
	
	function kelas_th_ajar($id_m_th_ajaran)
	{
		$this->db->select('*');
		$this->db->from('m_kelas');
		$this->db->where('id_m_kelas not in (select id_m_kelas from a_kelas where id_m_th_ajaran ='.$id_m_th_ajaran.')');
		$this ->db->order_by('id_m_kelas');

		$query = $this->db->get();		
		return $query->result();
	}
	
	function save($dataInsert)
	{
		$query = $this->db->insert('a_kelas', $dataInsert);
		return $query;
	}
	
	function delete($id_a_kelas)
	{
		$this->db->where('id_a_kelas', $id_a_kelas);
		$delete = $this->db->delete('a_kelas');
		return $delete;
	}
}